import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Fee {
    public static  double  getTelCost(long time) {
        double fee;
        if(time <= 20){
            fee = 0.05*time;
        }else{
            fee = 1.00 + (time - 20)*0.1;
        }
        BigDecimal b = new BigDecimal(fee);
        fee = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return fee;
    }

    public static Date StrToDate(String str) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = format.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static long calculateTimeSpan(Date startTime, Boolean inDayLightSavingOfStartTime, Date endTime, boolean inDayLightSavingOfEndTime){
        long between,time;
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(startTime);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(endTime);
        between = cal2.getTime().getTime()-cal1.getTime().getTime();
        if(between<0) {
            time =( (cal2.getTime().getTime()-cal1.getTime().getTime())/1000)/60;
        } else {
            time = (between/1000+59)/60;
        }
        if(inDayLightSavingOfStartTime){
            time -=60;
        }
        if(inDayLightSavingOfEndTime){
            time += 60;
        }
        if(time>1800 || time <0){
            System.out.println("err");
            return 0;
        }else{
            return time;
        }
    }

}